const { DataTypes } = require("sequelize")
const sequelize = require("../config/database")

const Unit = sequelize.define(
  "unit",
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    building_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: {
        model: "building",
        key: "id",
      },
    },
    number: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    polygon: {
      type: DataTypes.JSON,
      allowNull: false,
    },
    delete_at: {
      type: DataTypes.DATE,
      allowNull: true,
    },
    create_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
    },
    update_at: {
      type: DataTypes.DATE,
      allowNull: true,
    },
  },
  {
    timestamps: true,
    createdAt: "create_at",
    updatedAt: "update_at",
    deletedAt: "delete_at",
    tableName: "unit",
  }
)

module.exports = Unit
